﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using VOL;
using DAL;

namespace BLL
{
    public class LoaiHangHoaBL
    {
        private DataAccess dataAccess;
        public LoaiHangHoaBL()
        {
            dataAccess = new DataAccess();
        }

        public DataTable GetData()
        {
            string strSql = "SELECT * FROM tbl_LoaiHangHoa ORDER BY MaLoaiHangHoa DESC ";
            return dataAccess.GetData(strSql);
        }

        //Thêm
        public bool insertLoaiHangHoa(LoaiHangHoa obj)
        {
            SqlParameter[] param = new SqlParameter[1];
            param[0] = new SqlParameter("@TenLoaiHangHoa", SqlDbType.NVarChar) { Value = obj.TenLoaiHangHoa };

            string strSql = "INSERT INTO tbl_LoaiHangHoa(TenLoaiHangHoa) VALUES (@TenLoaiHangHoa)";
            dataAccess.Execute(strSql, param);

            return true;
        }

        ////Xóa
        public bool deleteChungLoai(LoaiHangHoa obj)
        {
            SqlParameter[] param = new SqlParameter[1];
            param[0] = new SqlParameter("@MaLoaiHangHoa", SqlDbType.Int) { Value = obj.MaLoaiHangHoa };

            string strSql = "DELETE FROM tbl_LoaiHangHoa WHERE MaLoaiHangHoa = @MaLoaiHangHoa";
            dataAccess.Execute(strSql, param);
            return true;
        }

        ////Sửa
        public bool updateLoaiHangHoa(LoaiHangHoa obj)
        {
            SqlParameter[] param = new SqlParameter[2];
            param[0] = new SqlParameter("@TenLoaiHangHoa", SqlDbType.NVarChar) { Value = obj.TenLoaiHangHoa };
            param[1] = new SqlParameter("@MaLoaiHangHoa", SqlDbType.Int) { Value = obj.MaLoaiHangHoa };

            string strSql = "UPDATE tbl_LoaiHangHoa SET " +
                            "TenLoaiHangHoa = @TenLoaiHangHoa " +
                            "WHERE MaLoaiHangHoa = @MaLoaiHangHoa";
            dataAccess.Execute(strSql, param);
            return true;
        }

        ////Tìm theo Mã Loại Hàng Hóa
        public DataTable searchIDLoaiHangHoa(int maLoaiHangHoa)
        {
            SqlParameter[] param = new SqlParameter[1];
            param[0] = new SqlParameter("@MaLoaiHangHoa", SqlDbType.Int) { Value = maLoaiHangHoa };

            string strSql = "SELECT * FROM tbl_LoaiHangHoa WHERE MaKhach = @MaLoaiHangHoa";
            return dataAccess.GetData(strSql, param);
        }
    }
}
